﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data.SQLite;
using Microsoft.Win32;
using System.IO;
using System.ComponentModel;
using System.Collections;
using translator.Command;
using System.Runtime.InteropServices;
//using baidu;
using Thrift;
using Thrift.Protocol;
using Thrift.Transport;
using System.Net.Sockets;
using Thrift.Transport.Client;
using System.Threading;
using System.Runtime.CompilerServices;

namespace translator
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindowModel model;
        public string filepath ="";
        SQLiteConnection connection;
        public int Translated = 0;
        public Lang OriginalLanguage = Lang.English;     //源语言
        public Lang TranslatedLanguage = Lang.English;    //翻译语言
        public StringEditWindow stringEditWindow;
        public SQLiteConnection Connection
        {
            get {return connection; }
            set { connection = value; }
        }

        public  MainWindow()
        {
            this.model = new MainWindowModel(this);
            InitializeComponent();
            this.DataContext = model;
            this.Datagrid.DataContext = model;
            this.HintTable.DataContext = model;
            this.MMenu.DataContext = model;
            this.stringEditWindow = new StringEditWindow(this);
            PrepareIni();
            //Task task = test();
            //Task.WaitAll(task);
            //task.RunSynchronously();
            //if(!task.IsCompleted) task.Wait();

            pbStatus.Value = 100;
            //this.Sta.Content = "123123123";
        }
        public void Log(string ss)
        {
            
            LogBox.AppendText(System.DateTime.Now.ToString() + ": " + ss + "\n");
            LogBox.ScrollToEnd();
        }

        


        public void PrepareIni()
        {
            
            string INIPath = Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "Config.ini";
            if (!File.Exists(INIPath))
            {
                File.WriteAllText(INIPath,Properties.Resources.DefaulTranslateAPI,Encoding.UTF8);
            }
            Const.SetFilePath(INIPath);
            //Log(INIPath);  
        }

        private static CancellationToken MakeTimeoutToken(int msec = 15_000)
        {
            var token = new CancellationTokenSource(msec);
            return token.Token;
        }

        public void TranslateSelectedStringsByAPI(TranslateAPI translateAPI)
        {
            Dictionary<int, string> originalDict = new Dictionary<int, string>();
            foreach (StringInfo stringInfo in Datagrid.SelectedItems)
            {
                originalDict[stringInfo.Sid] = stringInfo.Original;
            }
            Task task = TraslateStringsByAPI(originalDict, translateAPI);
        }

        public async Task TraslateStringsByAPI(Dictionary<int, string> orig,TranslateAPI translateAPI)
        {

            Dictionary<int, string> dict = null;
            dict = await TranslateStrings(orig,translateAPI);
            if(dict == null) { Log("Auto Translate filed"); return; }
            else
            {
                foreach(int key in orig.Keys)
                {
                    UpdateStringTranslated(key, orig[key], false, false);
                }
                Datagrid.Items.Refresh();
                Log("Auto Translate success");
            }
        }
        
        public async Task<Dictionary<int,string>> TranslateStrings(Dictionary<int,string> orig,TranslateAPI translateAPI)
        {
            
            TTransport transport = null;
            TProtocol protocol = null;
            translateService.Client client = null;
            if (null == await ConnectAutoTranslator(transport, protocol, client)) { return null; };
            Dictionary<int, string> res = null;

            Task<Dictionary<int, string>> task1 = null;
            switch (translateAPI)
            {
                case TranslateAPI.Alibaba:
                    {

                        break;
                    }
                case TranslateAPI.Baidu:
                    {
                        string appid = Const.ReadIniData("TranslaterAPI", "Baidu_AppId", "");
                        string key = Const.ReadIniData("TranslaterAPI", "Baidu_Key", "");
                        int charcout = 0;
                        try
                        {
                            charcout = int.Parse(Const.ReadIniData("APIusage", "Baidu_CharCount", ""));
                        }
                        catch (Exception pe) { Log("Baidu_CharCount:" + pe.Message); }
                        if (charcout == 0 || appid == "" || key == "") { Log("BaiduAPI params wrong"); res = null; }
                        else { Log("Auto Translating..."); task1 = client.TranslateByBaidu(orig, appid, key, charcout, MakeTimeoutToken(300_000)); }
                        break;
                    }
                case TranslateAPI.DeepL:
                    {
                        break;
                    }
                case TranslateAPI.Google:
                    {
                        break;
                    }
                case TranslateAPI.Microsoft:
                    {
                        break;
                    }
                case TranslateAPI.Youdao:
                    {
                        break;
                    }
                default: { break; }
            }
            res = await task1;
            DisposeAutoTranslator(transport, protocol, client);
            return res;
        }


        public async Task<string> ConnectAutoTranslator(TTransport transport, TProtocol protocol, translateService.Client client)
        {
            DisposeAutoTranslator(transport, protocol, client);
            Log("make AutoTranslator client");
            var TConfig = new TConfiguration();
            transport = null;
            transport = new TSocketTransport(host: "localhost", 49153, TConfig);
            transport = new TFramedTransport(transport);
            protocol = new TBinaryProtocol(transport);
            client = new translateService.Client(protocol);
            await client.OpenTransportAsync(MakeTimeoutToken(5_000));
            string res = await client.ping(MakeTimeoutToken(3_000));
            if(res != null)
            {
                Log(res);
                Log("client make success");
            }
            Log("client make failed");
            return res;
        }
        public void DisposeAutoTranslator(TTransport transport, TProtocol protocol, translateService.Client client)
        {
            if(null == client || null == protocol || null == transport) { return; }
            Log("Dispose AutoTranslator");
            if (null != client) {  client.Dispose();client = null; }
            if(null != protocol) { protocol.Dispose(); protocol = null; }
            if(null != transport) {transport.Dispose();transport = null; }
            Log("Dispose AutoTranslator success");
        }

        public async Task test()
        {

            Log("测试sayhello:" + "start");
            var TConfig = new TConfiguration();
           
            TTransport transport = null;
            transport = new TSocketTransport(host: "localhost", 49153, TConfig);
            transport = new TFramedTransport(transport);
            TProtocol protocol = new TBinaryProtocol(transport);

            translateService.Client client = new translateService.Client(protocol);
            await client.OpenTransportAsync();
            Log("测试sayhello:" + "start1");
            /*
            Task task1 = client.OpenTransportAsync();
            task1.Wait();*/
            Log("测试sayhello:" + "in");
            //string res = await client.sayHello("1231243",MakeTimeoutToken());
            string res = await client.ping();


            Dictionary<int, string> orig = new Dictionary<int, string>();
            string appid = Const.ReadIniData("TranslaterAPI", "Baidu_AppId", "");
            string key = Const.ReadIniData("TranslaterAPI", "Baidu_Key", "");
            int charcout = 0;
            try
            {
                charcout = int.Parse(Const.ReadIniData("APIusage", "Baidu_CharCount", "")) ;
            }
            catch(Exception pe) { Log("Baidu_CharCount:" + pe.Message); }
            if (charcout == 0 || appid =="" || key == "" ) { return; }
            Dictionary<int, string> dicc = await client.TranslateByBaidu(orig,appid,key,charcout);
            Log("测试sayhello:" + "out");
            Log("测试sayhello:" + res);

            return;
            /*
            try { 
                

            }
            catch(Exception e1) { Log(e1.StackTrace); }
            finally
            {
                if (null != transport)
                {
                    //close
                    transport.Close();
                }
            }*/


            /*
            HelloWorld hello = new HelloWorld();
            java.util.HashMap hashMap = new java.util.HashMap();
            hashMap.put(5, "He'd like more time to think things over.");
            var map = hello.getHashMap(hashMap);

            Log(hello.sayHello());
            Log(map.get(5) as string);
            */
            /*
            try { 
            BaiduTranslate baiduTranslate = new BaiduTranslate();

            java.util.HashMap hashMap = new java.util.HashMap();
            hashMap.put(5, "He'd like more time to think things over.");

            hashMap = (java.util.HashMap)baiduTranslate.translateContext(hashMap, "20230517001680288", "RQzgsIjqKKUQwYzkhPJS", 6000);
            string res = hashMap.get(5) as string;
            Log(res);
            }
            catch (Exception e)
            { Log(e.ToString()); }*/


        }
        public void ValidateRowToState(int t)
        {
            var vcmd = connection.CreateCommand();
            vcmd.CommandText = @"UPDATE StringInfo SET Status = @Status WHERE id = @Sid";
            var P_Sid = vcmd.CreateParameter();
            var P_Status = vcmd.CreateParameter();
            P_Status.ParameterName = "Status";
            P_Sid.ParameterName = "Sid";
            vcmd.Parameters.Add(P_Sid);
            vcmd.Parameters.Add(P_Status);
            P_Status.Value = t;

            int allct = 0;
            int lct = 0;
            foreach (StringInfo info in Datagrid.SelectedItems)
            {
                P_Sid.Value = info.Sid;
                int count = vcmd.ExecuteNonQuery();
                
                if (count > 0)
                {
                    if(t == 2)
                    {
                        if(this.model.StringLst[StringDict[info.Sid]].Status!=2)
                        {
                            this.model.StringLst[StringDict[info.Sid]].Status = t;
                            this.Translated++;
                            this.RefresgStringHeaderUI();
                        }
                    }
                    else
                    {
                        if(this.model.StringLst[StringDict[info.Sid]].Status == 2)
                        {
                            this.Translated--;
                            this.RefresgStringHeaderUI();
                        }
                        this.model.StringLst[StringDict[info.Sid]].Status = t;
                    }
                    
                }
                else { lct++; }
                allct++;
            }
            Datagrid.Items.Refresh();
            Log("已更新StringTable,共" + allct + "条,失败" + lct + "条");
            vcmd.Dispose();
        }

        public void disConnect()
        {
            if (this.Connection != null)
            {
                this.Connection.Dispose();
                this.Connection = null;
            }
            CommandSelectAll?.Dispose();
            CommandSelectAll = null;
            cmd?.Dispose();
            cmd = null;
            System.Data.SQLite.SQLiteConnection.ClearAllPools();
            GC.Collect();
            GC.WaitForPendingFinalizers();
            //CommandManager.InvalidateRequerySuggested();
        }
         

        public void NewStringTableFromCurrentStringTable(Lang newLang,string fileName)        //从当前String表生成新的String表   (参数1:新String表Translated语言,参数2:新String表存放路径)
        {

            disConnect();
            
            Const.CopyFile(filepath, fileName);
            if (!this.OpenDatabase(fileName)) { this.Log("End Load Process."); return; }
            ReadDataBase();
            this.GetHintTable();
            this.StringHeader.Header = "String[" + this.Translated + "/" + this.model.StringLst.Count + "]";     //UI刷新,写在这里不妥当
            this.Datagrid.DataContext = this.model;
            this.Log("Load String table: " + fileName + " Successed!");
            Title = "Twine引擎游戏翻译器  " + fileName;
            if (ChangeTranslatedLanguage(newLang)) 
            {
                Log("新建String表成功,Path: "+fileName);
            }

        }

        public bool ChangeTranslatedLanguage(Lang newLang)
        {

            var cmd = new SQLiteCommand(@"delete from TranslatedLanguage", Connection);
            int count = cmd.ExecuteNonQuery();
            if (count > 0){}
            else 
            {
                Log("Translated语言更新失败");
                return false;
            }
            cmd.CommandText = @"insert into TranslatedLanguage(Language) values('"+ newLang.ToString() + "')";
            count = cmd.ExecuteNonQuery();
            if (count > 0)
            {
                Log("Translated语言更新成功");

            }
            else
            {
                Log("Translated语言更新失败");
                return false;
            }
            TranslatedLanguage = newLang;
            RefreshStateUI();
            cmd.Dispose();
            return true;
        }





        public bool OpenDatabase(string filepath)   //打开新的数据库
        {
            Log("Try to open file " + filepath + " as String table...");
            try {
                if (Connection!=null)
                {
                    disConnect();
                }
                Connection = new SQLiteConnection(filepath);
                Connection.ConnectionString = "Data Source=" + filepath;
                Connection.Open();
                this.filepath = filepath;
                Log("File " + filepath + " as String table open successed!");
                //CommandManager.InvalidateRequerySuggested();
                return true;
            }
            catch (Exception e)
            {
                Log("Exception:" + e);
            }
            Log("File " + filepath + " as String table open filed!");
            return false;
        }
        SQLiteCommand CommandSelectAll;
        Dictionary<int, int> StringDict;  //Sid->index
        public void ReadDataBase()      //读数据库
        {
            this.GetTranslateInfo();
            Log("Try to read String table from file " + filepath + " ...");
            Translated = 0;                        //初始化数据
            if (CommandSelectAll == null)
            {
                CommandSelectAll = new SQLiteCommand(@"select * from StringInfo", Connection);
            }
            List<StringInfo> lst = new List<StringInfo>();
            StringDict = new Dictionary<int, int>();
            var reader = CommandSelectAll.ExecuteReader();
            while (reader.Read())
            {
                StringInfo stmp = new StringInfo(reader.GetInt32(0), reader.GetFloat(1), reader.GetString(2), reader.GetString(3), reader.GetString(4), reader.GetString(5), reader.GetInt32(6));
                lst.Add(stmp);
                StringDict.Add(stmp.Sid, lst.Count - 1);
                if (reader.GetInt32(6) == 2) { Translated++; };
            }
            reader.Close();
            this.model.StringLst = new ObservableCollection<StringInfo>(lst);
            Log("String table read successed!");
        }
        public string HtmlName = "None";
        public bool GetTranslateInfo()  //获得翻译信息    (源语言,翻译语言,)
        {
            var cmd = new SQLiteCommand(@"select * from OriginalLanguage", Connection);
            var reader = cmd.ExecuteReader();
            if (reader.Read()){OriginalLanguage = Const.ToEnum<Lang>(reader.GetString(0));}else { reader.Close(); return false; }
            reader.Close();
            cmd.CommandText = @"select * from TranslatedLanguage";
            reader = cmd.ExecuteReader();
            if (reader.Read()) { TranslatedLanguage = Const.ToEnum<Lang>(reader.GetString(0)); } else { reader.Close(); return false; }
            reader.Close();
            cmd.CommandText = @"select * from HtmlName";
            reader = cmd.ExecuteReader();
            if (reader.Read()) { HtmlName = reader.GetString(0); }
            reader.Close();
            RefreshStateUI();
            return true;
        }
        public void RefreshStateUI()
        {
            Sta.Content = "[" + OriginalLanguage.ToString() + "]->[" + TranslatedLanguage + "] "+HtmlName;
        }
        public void RefresgStringHeaderUI()
        {
            this.StringHeader.Header = "String[" + this.Translated + "/" + this.model.StringLst.Count + "]";
        }
        public Dictionary<String, String> hintTable = new Dictionary<string, string>();        //Hint哈希表 key:OriginalWord value:TranslatedHint
        public void GetHintTable()      //根据句子生成提示表(仅限英语类语言,(目前仅限英语))
        {
            
            if (OriginalLanguage != Lang.English) { return; }
            Dictionary<string,int> ht = new Dictionary<string, int>();
            foreach(StringInfo i in this.model.StringLst)
            {
                GetWord(in ht, i.Original);
            }
            List<HintInfo> hlst = new List<HintInfo>(); 
            foreach(var i in ht)
            {
                
                if(i.Value > 0) { hintTable[i.Key] = ""; 
                hlst.Add(new HintInfo(i.Key, ""));
            }
            }
            this.model.HintLst = new ObservableCollection<HintInfo>(hlst);

        }
        
        public void LoadHint()      //导入翻译词典    (未实现)
        {

        }
        public string TranslateHint(string ss)  //用翻译API直接翻译Hint单词        (未实现)
        {
            return "";
        }
        public void GetWord(in Dictionary<string, int> HintTable,string ss)     //用于生成hinttable表
        {
            string[] arr = ss.Split(new char[]{' ',',','?','!','\'','\"','\n','\t','.' ,'<','>','[',']','|','{','}','(',')',';',':'});

            bool judge;
            HashSet<char> hst = new HashSet<char>(new List<char>() {'0','1','2','3','4','5','6','7','8','9','$','￥', '￡' });
           
            for(int i = 0; i < arr.Length;i++)
            {
                string s = arr[i].Trim().ToLower();
                if(s.Length<4) { continue; }
                judge = true;
                foreach(char c in s)
                {
                    if (hst.Contains(c)) { judge = false;break; }
                }
                if (!judge) { continue; }
                if (HintTable.ContainsKey(s)) { HintTable[s] += 1; }
                else { HintTable.Add(s, 1); }
                
            }
        }
        public string GetHint(string ss)     //根据要翻译的句子和提示表生成提示(目前仅限英语)
        {
            if (OriginalLanguage != Lang.English) { return ""; }
            string[] arr = ss.Split(new char[] { ' ', ',', '?', '!', '\'', '\"', '\n', '\t', '.', '<', '>', '[', ']', '|', '{', '}', '(', ')', ';', ':' });
            string res = "";
            for (int i = 0; i < arr.Length; i++)
            {
                
                string s = arr[i].Trim().ToLower();
                if (s == "" || s.Length < 4) { continue; }
                if (hintTable.ContainsKey(s) && hintTable[s] != "") { res += s + "\t" + hintTable[s] + "\n"; }

            }
            return res;
        }

        public int EditingStringIndex; //编辑的字符串行索引

        IDbCommand cmd;
        IDbDataParameter Param_Translated;
        IDbDataParameter Param_Sid;
        public bool UpdateStringTranslated(int sid, string Translated,bool refresh = true,bool focus = true)          //根据StringId更新String翻译 StringEdit窗口点击OK后,调用主窗口此函数进行后续操作
        {
            if(cmd == null)
            { 
                cmd = connection.CreateCommand();
                cmd.CommandText = @"UPDATE StringInfo SET Translated = @Translated,Status = 2 WHERE id = @Sid";
                Param_Translated = cmd.CreateParameter();
                Param_Sid = cmd.CreateParameter();
                Param_Translated.ParameterName = "Translated";
                Param_Sid.ParameterName = "Sid";
                cmd.Parameters.Add(Param_Translated);
                cmd.Parameters.Add(Param_Sid);
            }
            Param_Translated.Value = Translated;
            Param_Sid.Value = sid;
            int count = cmd.ExecuteNonQuery();
            
            if (count > 0)
            {
                Log("String sid" + sid + "更新成功");
                if (!StringDict.ContainsKey(sid)) { return false; }
                StringInfo tmp = this.model.StringLst[StringDict[sid]];
                tmp.Translated = Translated;
                tmp.Status = 2;
                /*
                if (sid == tmp.Sid)
                {
                    tmp.Translated = Translated;
                    tmp.Status = 2;
                }
                else
                {
                    for(int i = 0; i < this.model.StringLst.Count;i++)
                    {
                        if(this.model.StringLst[i].Sid == sid)
                        {
                            this.model.StringLst[i].Translated = Translated;
                            if(this.model.StringLst[i].Status !=2)
                            {
                                this.model.StringLst[i].Status = 2;
                                
                            }
                            
                            Log("警告:EditingStringIndex 不准确" + EditingStringIndex+" "+i);
                            break;
                        }
                    }
                }
                */
                if(refresh)Datagrid.Items.Refresh();
                if(focus)ToFocusStringTable();

                return true;
            }
            else
            {
                Log("String sid" + sid + "更新失败");
                return false;
            }
        }
        public void ToFocusStringTable()
        {
            Datagrid.Focus();
            Keyboard.Focus(Datagrid);
            FocusManager.SetFocusedElement(this, Datagrid);
        }

        private void Window_Closed(object sender, EventArgs e)
        {
            Application.Current.Shutdown();
        }


        private void HintTable_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
        {
            HintInfo htmp = (e.Row.Item as HintInfo);
            hintTable[htmp.OriginWord] = htmp.TranslatedHint = (e.EditingElement as TextBox).Text;
            
            
        }

        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            var conn = new SQLiteConnection(Properties.Settings.Default.DictionaryPath);
            conn.ConnectionString = "Data Source=" + Properties.Settings.Default.DictionaryPath;
            try 
            {
                conn.Open();
            }
            catch(Exception ee) { Log("Dictionary connect failed,Exception:" + ee.StackTrace); }
            var comd = conn.CreateCommand();
            comd.CommandText = @"select TranslatedHint from hint where OriginalWord = @OriginalWord";
            var P_OriginalWord = comd.CreateParameter();
            P_OriginalWord.ParameterName = "OriginalWord";
            comd.Parameters.Add(P_OriginalWord);
            try
            {
                foreach(HintInfo htif in HintTable.SelectedItems)
                {
                    P_OriginalWord.Value = htif.OriginWord;
                    var reader = comd.ExecuteReader();
                    while(reader.Read())
                    {
                        htif.TranslatedHint = reader.GetString(0);
                        hintTable[htif.OriginWord] = htif.TranslatedHint;
                    }
                    reader.Close();
                }
            }
            catch (Exception eee)
            {
                Log("read dictionary failed,Exception:" + eee.StackTrace);
            }
            comd.Dispose();
            conn.Dispose();
            HintTable.Items.Refresh();
        }

        private void MenuItem_Click_1(object sender, RoutedEventArgs e)
        {
            foreach (HintInfo htif in HintTable.SelectedItems)
            {
                htif.TranslatedHint = htif.OriginWord;
                hintTable[htif.OriginWord] = htif.TranslatedHint;
            }
            HintTable.Items.Refresh();
        }

        private void MenuItem_Click_2(object sender, RoutedEventArgs e)
        {
            HintTable.SelectedItems.Clear();
            foreach(HintInfo ht in this.model.HintLst)
            {
                if(ht.TranslatedHint.Trim() == "")
                {
                    HintTable.SelectedItems.Add(ht);
                }
            }
        }

        private void MenuItem_Click_3(object sender, RoutedEventArgs e)
        {
            foreach (HintInfo htif in HintTable.SelectedItems)
            {
                htif.TranslatedHint = "";
                hintTable[htif.OriginWord] = htif.TranslatedHint;
            }
            HintTable.Items.Refresh();
        }

        private void MenuItem_Click_4(object sender, RoutedEventArgs e)
        {
            LogBox.Clear();
        }

        private void MenuItem_Click_5(object sender, RoutedEventArgs e)
        {
            TranslateSelectedStringsByAPI(TranslateAPI.Baidu);
        }
    }

    public class MainWindowModel:INotifyPropertyChanged
    {
        private ObservableCollection<StringInfo> stringLst;
        public ObservableCollection<StringInfo> StringLst
        { get { return stringLst; } set { stringLst = value; if (PropertyChanged != null) PropertyChanged.Invoke(this, new PropertyChangedEventArgs("StringLst")); } }
        private ObservableCollection<HintInfo> hintLst;
        public ObservableCollection<HintInfo> HintLst
        {
            get { return hintLst; }
            set { hintLst = value;  if (PropertyChanged != null) PropertyChanged.Invoke(this, new PropertyChangedEventArgs("HintLst"));  }
        }

        public LoadOrNewStringTableCommand LoadOrNewStringTableCommand { get; set; }
        public EditStringCommand EditStringCommand { get; set; }
        public StringUpKeyDownCommand StringUpKeyDownCommand { get; set; }
        public StringDownKeyDownCommand StringDownKeyDownCommand { get; set; }
        public CreateDBFromCurrentCommand CreateDBFromCurrentCommand { get; set; }
        public ValidateToCompletedTranslatedCommand ValidateToCompletedTranslatedCommand { get; set; }
        public ValidateToNoNeedToTranslateCommand ValidateToNoNeedToTranslateCommand { get; set; }
        public ValidateToNotTranslatedCommand ValidateToNotTranslatedCommand { get; set; }
        public ValidateToTranslatedButNotCurrectCommand ValidateToTranslatedButNotCurrectCommand { get; set; }
        public OpenOptionsCommand OpenOptionsCommand { get; set; }
        public ReadHintFromDictCommand ReadHintFromDictCommand { get; set; }
        public TranslateSelectedStringByAPICommand TranslateSelectedStringByAPICommand { get; set; }
        public MainWindowModel(MainWindow mainWindow)
        {
            LoadOrNewStringTableCommand = new LoadOrNewStringTableCommand(mainWindow);
            EditStringCommand = new EditStringCommand(mainWindow);
            StringUpKeyDownCommand = new StringUpKeyDownCommand(mainWindow);
            StringDownKeyDownCommand = new StringDownKeyDownCommand(mainWindow);
            CreateDBFromCurrentCommand = new CreateDBFromCurrentCommand(mainWindow);
            ValidateToCompletedTranslatedCommand = new ValidateToCompletedTranslatedCommand(mainWindow);
            ValidateToNoNeedToTranslateCommand = new ValidateToNoNeedToTranslateCommand(mainWindow);
            ValidateToNotTranslatedCommand = new ValidateToNotTranslatedCommand(mainWindow);
            ValidateToTranslatedButNotCurrectCommand = new ValidateToTranslatedButNotCurrectCommand(mainWindow);
            OpenOptionsCommand = new OpenOptionsCommand(mainWindow);
            ReadHintFromDictCommand = new ReadHintFromDictCommand(mainWindow);
            TranslateSelectedStringByAPICommand = new TranslateSelectedStringByAPICommand(mainWindow);
        }

        public event PropertyChangedEventHandler PropertyChanged;
    }


    public class StringInfo
    {
        public int Sid { get; set; }
        public float Probably { get; set; }
        public string Type { get; set; }
        public string Original { get; set; }
        public string Translated { get; set; }
        public string Context { get; set; }
        public int Status { get; set; }         //0:未翻译 1:已翻译未验证 2:已验证
        public StringInfo() { }
        public StringInfo(int Sid,
                         float Probably,
                         string Type,
                         string Original,
                         string Translated,
                         string Context,
                         int Status)
        {
            this.Sid = Sid;
            this.Probably = Probably;
            this.Type = Type;
            this.Original = Original;
            this.Translated = Translated;
            this.Context = Context;
            this.Status = Status;
        }

    }

    public class HintInfo
    {
        public string OriginWord { get; set; }
        public string TranslatedHint { get; set; }
        public HintInfo() { this.OriginWord = "";this.TranslatedHint = ""; }
        public HintInfo(string ori,string tra)
        {
            this.OriginWord = ori;
            this.TranslatedHint = tra;
        }
    }

    
}


